<template>
  <div class="">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="加油站点" prop="stationId">
        <el-select v-model="queryParams.stationId" placeholder="请选择加油站点" clearable>
          <el-option v-for="item in stationList" :key="item.stationId" :label="item.stationName"
            :value="item.stationId" />
        </el-select>
      </el-form-item>
      <el-form-item label="加油枪号" prop="gunNo">
        <el-input v-model="queryParams.gunNo" placeholder="请输入加油枪号" clearable maxlength="2" />
      </el-form-item>
      <!-- <el-form-item label="支付状态" prop="paidStatus">
        <el-select v-model="queryParams.paidStatus" placeholder="请选择支付状态" clearable>
          <el-option v-for="(value, key) in paidStatusMap" :key="key" :label="value" :value="key" />
        </el-select>
      </el-form-item> -->
      </el-form-item>
      <el-form-item label="开始时间" prop="startTime">
        <el-date-picker v-model="queryParams.startTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="请选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-date-picker v-model="queryParams.endTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择结束时间" default-time="23:59:59">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <!-- <el-button type="primary" plain icon="el-icon-download" size="mini" @click="handleExport"
          :disabled="total<=0">导出</el-button> -->
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="枪号" align="center" prop="gunNo" width="60" />
      <el-table-column label="油品" align="center" prop="prName" width="60" />
      <el-table-column label="单价" align="center" prop="price" width="80" />
      <el-table-column label="升数" align="center" prop="vol" width="100" />
      <el-table-column label="金额" align="center" prop="fuelAmt" />
      <el-table-column label="实收金额" align="center" prop="realAmt" />
      <el-table-column label="优惠金额" align="center" prop="discAmt" />
      <el-table-column label="订单时间" align="center" prop="createTime" width="150" />
      <!-- <el-table-column label="班次" align="center" prop="shiftNo" /> -->
      <el-table-column label="员工姓名" align="center" prop="empName" />
      <el-table-column label="会员" align="center" prop="memberName" />
      <el-table-column label="支付方式" align="center">
        <template slot-scope="scope">
          {{scope.row.paidStatus>0?scope.row.paidName:'---'}}
        </template>
      </el-table-column>
      <el-table-column label="支付时间" align="center" prop="paidTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleView(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 订单详情 -->
    <el-dialog :title="title" :visible.sync="open" width="860px" append-to-body>
      <el-descriptions class="margin-top" :column="3" border>
        <!-- <template slot="extra">
            <el-button type="primary" size="small">操作</el-button>
          </template> -->
        <el-descriptions-item>
          <template slot="label"> 站点 </template>
          {{form.stationName}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 枪号/油品 </template>
          {{form.gunNo}} / {{form.prName}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 班次 </template>
          {{form.shiftNo}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 提枪时间 </template>
          {{form.startTime}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 挂枪时间 </template>
          {{form.endTime}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 单价 </template>
          {{form.price}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 升数 </template>
          {{form.vol}}
        </el-descriptions-item> <el-descriptions-item>
          <template slot="label"> 累计升数 </template>
          {{form.totalVol}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 累计金额 </template>
          {{form.totalAmt}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 金额 </template>
          {{form.fuelAmt}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 实收金额 </template>
          {{form.realAmt}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 优惠金额 </template>
          {{form.discAmt}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 员工姓名 </template>
          {{form.empName}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 员工卡号 </template>
          {{form.empCard}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 会员姓名 </template>
          {{form.memberName}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 会员卡号 </template>
          {{form.memberCard}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 会员车牌 </template>
          {{form.memberCarNo}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 创建时间 </template>
          {{form.createTime}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 付款方式 </template>
          {{form.paidName}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 付款时间 </template>
          {{form.paidTime}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label"> 授权ID </template>
          {{form.authId}}
        </el-descriptions-item>

      </el-descriptions>
      <!-- <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div> -->
    </el-dialog>
  </div>
</template>

<script>
  import {
    getInfo
  } from "@/api/login"
  import {
    fuelOrder,
    fuelOrderSummary,
    fuelOrderExport
  } from "@/api/fleet";
  export default {
    name: "Fuel",
    data() {
      return {
        paidStatusMap: {
          '0': '未支付',
          '1': '已支付'
        },
        buttonLoading: false,
        loading: true,
        showSearch: true,
        total: 0,
        dataList: [],
        title: "",
        open: false,
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          stationId: undefined,
          gunNo: undefined,
          prId: undefined,
          companyId: undefined,
          memberId: undefined,
          gradeId: undefined,
          shiftNo: undefined,
          empId: undefined,
          paidStatus: undefined,
          paidId: undefined,
          startTime: '',
          endTime: undefined
        },
        stationList: [],
        prList: [],
        empList: [],
        paidList: [],
        form: {

        },
        rules: {

        }
      };
    },
    created() {
      console.log('----created----')
      this.getDropList();
      let range = this.timeForRange(-7)
      // console.log('日期范围', range)
      this.queryParams.startTime = range[0]
      this.queryParams.endTime = range[1]
    },
    activated() {
      console.log('----activated----')
      this.getList();
    },
    methods: {
      getDropList() {
        getInfo().then(rsp => {
          console.log(rsp)
          this.stationList = rsp.data.allowStation
        })
        // prList().then(rsp => {
        //   this.prList = rsp.data
        // })
        // paidList().then(rsp => {
        //   this.paidList = rsp.data
        // })
        // listEmpSample().then(rsp => {
        //   this.empList = rsp.data
        // })
      },
      getList() {
        this.loading = true;
        fuelOrder(this.queryParams).then(response => {
          this.dataList = response.data.rows;
          this.total = parseInt(response.data.total);
          this.loading = false;
        }).catch(() => this.loading = false);
      },
      cancel() {
        this.open = false;
        this.reset();
      },
      reset() {
        this.form = {};
        this.resetForm("form");
      },
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      handleExport() {
        this.download('/crm/fleet/fuelOrderExport', {
          ...this.queryParams
        }, `加油订单_${new Date().getTime()}.xlsx`)
      },
      handleView(row) {
        this.reset();
        this.form = row;
        this.open = true;
        this.title = `加油订单详情 - ${row.id}`;
      }
    }
  };
</script>
